const db = require('../DBcofig/DBConnection')
module.exports = {
    getPackageType(req, res) {
        let { page, limit, search } = req.query
        let sql = 'SELECT * FROM packagetype left join medicalplan on medicalplan.type_id=packagetype.typeId'
        let arr = []
        db.dbconfig(res, sql, arr, function(data) {
            // console.log(data, "啦啦啦");
            if (data != null) {
                res.send({
                    code: 200,
                    msg: '查询成功',
                    data: data
                });
            } else {
                res.send({
                    code: 404,
                    msg: '查询失败',
                });
            }

        })

    },
    addPackageType(req, res) {
        let { typeName, typeStatus, typeDesc } = req.body;
        let sql = 'insert into packageType values (null,?,?,?)';
        let arr = [typeName, typeStatus, typeDesc];
        db.dbconfig(res, sql, arr, function(data) {
            // console.log(data, "啦啦啦");
            if (data.affectedRows >= 1) {
                res.send({
                    code: 200,
                    msg: '新增成功',
                });
            } else {
                res.send({
                    code: 404,
                    msg: '新增失败',
                });
            }
        })
    },
    delPackageType(req, res) {
        let { id } = req.body;
        console.log(id);
        let sql = 'delete from packageType where typeId=?';
        let arr = [id];
        db.dbconfig(res, sql, arr, function(data) {
            console.log(data, "啦啦啦");
            if (data.affectedRows >= 1) {
                res.send({
                    code: 200,
                    msg: '删除成功',
                });
            } else {
                res.send({
                    code: 404,
                    msg: '删除失败',
                });
            }
        })
    },
    getTypeName(req, res) {
        let { page, limit, search } = req.query
        let sql = 'SELECT * FROM packagetype '
        let arr = []
        db.dbconfig(res, sql, arr, function(data) {
            // console.log(data, "啦啦啦");
            if (data != null) {
                res.send({
                    code: 200,
                    msg: '查询成功',
                    data: data
                });
            } else {
                res.send({
                    code: 404,
                    msg: '查询失败',
                });
            }

        })

    },
}